<template>
  <div id="detail-classify">
    <div class="dc-title">
      <h3>基本信息</h3>
    </div>
    <div class="dc-base">
      <p>起投日期:{{timeCancel(detail.calRateBeginDate)}}</p>
      <p>结束日期:{{timeCancel(detail.calRateEndDate)}}</p>
      <p>投资金额:<span>{{detail.investNum}}</span>元</p>
      <p>到期收益:<span>{{detail.expectedReturn}}</span>元</p>
    </div>
    <div class="dc-definite">
      <div class="dcd-half">
        <div class="dc-top">
          <h3>车辆信息</h3>
          <a v-for="(curcar,index) in cars" @click="chooseCar(index)">{{index + 1}}</a>
        </div>
        <div class="dc-content">
          <p>车辆归属地：{{curCar.location ? curCar.location.value : ''}}
          </p>
          <p>车牌号：{{curCar.carNo}}</p>
          <p>品牌型号：{{curCarName}}</p>
          <p>车身颜色：{{curCar.color.value}}</p>
          <p>发动机号：{{curCar.engineNo}}</p>
          <p>车辆识别号：{{curCar.carIdNo}}</p>
          <p>车辆类型：{{curCar.carType.value}}</p>
          <p>使用性质：{{curCar.operateType}}</p>
          <p>所属企业：{{curCar.comName}}</p>
        </div>
      </div>
      <div class="dcd-half">
        <div class="dc-top">
          <h3>租赁信息</h3>
        </div>
        <div class="dc-content">
          <p>
            租赁司机：{{curCar.driverName}}
          </p>
          <p>
            滴滴账号：{{curCar.didiCode}}
          </p>
          <p>
            租赁状态：{{curCar.carStatus == 'DRIVERING' ? '运营中' : '停运'}}
          </p>
          <!--<p>-->
            <!--运营收入:-->
            <!--<span class="see-img"><img src="../../assets/details/see-report.png"/>-->
            <!--</span>-->
          <!--</p>-->
          <p>
            车辆位置:
            <router-link class="see-img" :to="{name:'map'}"><img src="../../assets/details/see-gps.png"/>
            </router-link>
          </p>
        </div>
        <div class="car-picture">
          <img src="../../assets/details/car.jpg" alt="">
        </div>
      </div>

    </div>

  </div>
</template>
<script>
  import {mapState, mapActions} from 'vuex'
  import api from '@/utils/api'

  export default {
    name: 'baseInfo',
    data() {
      return {
        detail: '',
        cars: '',
        curCar: '',
        curCarName: ''
      }
    },
    computed: {},
    methods: {
      timeCancel(time) {
        let date = new Date(time);
        let year = date.getFullYear();
        let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
        let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return year + "-" + month + "-" + day;
      },
      chooseCar(index) {
        console.log(index);
        this.curCar = this.detail.car;
        this.curCarName = this.cars[index]["CAROLLA"];
      },
      init() {
        let id = this.$router.currentRoute.params.productId;
        this.$store.dispatch('Get', {
          url: api.investView(id)
        }).then((res) => {
          this.detail = res.data;
          this.$store.dispatch('Get', {
            url: api.CarType
          }).then((res2) => {
            setTimeout(() => {
              this.cars = res2.data;
              this.chooseCar(0)
            }, 0);

          })
        })


      }
    },
    mounted() {
      this.init();
//      this.chooseCar(0);
    }
  }
</script>
<style lang="scss" scoped>
  #detail-classify {
    width: 100%;
    height: auto;
    margin-bottom: 35px;
    float: left;
    background: #fffbfb;
    padding: 15px 38px;
    .dc-title {
      width: 100%;
      float: left;
      h3 {
        width: 152px;
        height: 48px;
        line-height: 48px;
        text-align: center;
        color: #ffffff;
        background: #ff6430;
      }
    }
    .dc-base {
      width: 100%;
      border-bottom: 1px solid #111111;
      float: left;
      padding: 15px 0;
      p {
        width: 50%;
        float: left;
        text-align: left;
        line-height: 38px;
        font-size: 18px;
        color: #111111;
        span {
          color: #ff784b;
        }
      }

    }
    .dc-definite {
      width: 100%;
      float: left;
      .dcd-half {
        width: 50%;
        float: left;
        .dc-top {
          width: 100%;
          float: left;
          margin: 20px 0;
          h3 {
            width: 152px;
            height: 48px;
            line-height: 48px;
            text-align: center;
            color: #ffffff;
            background: #ff6430;
            float: left;
          }
          a {
            width: 34px;
            height: 34px;
            background: #ff6430;
            float: left;
            color: #ffffff;
            text-align: center;
            line-height: 34px;
            font-size: 18px;
            border-radius: 17px;
            margin: 10px 0 0 10px;
            cursor: pointer;
          }
        }
        .dc-content {
          width: 100%;
          float: left;
          p {
            text-align: left;
            margin: 6px 0;
            .see-img {
              width: 110px;
              vertical-align: middle;
              margin-left: 10px;
              img {
                width: 110px;
                vertical-align: middle;

              }
            }
          }
        }
        .car-picture {
          width: 100%;
          text-align: center;
          img {
            width: 60%;
          }
        }
      }

    }

  }
</style>
